/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import dao.DaoClientes;
import dao.DaoFilmes;
import java.awt.Color;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Tiago
 */
public class TelaReservas extends javax.swing.JInternalFrame {

    DaoClientes daoClientes = new DaoClientes();
    DaoFilmes daoFilmes = new DaoFilmes();
     boolean clienteSelecionado;
    public TelaReservas() {
        initComponents();
       
    }
    
    public void instrucoesDeUsoReserva(){
        JOptionPane.showMessageDialog(jPanelBuscaCliente, "Instruções de Uso:"+
                "\n 1º Busque o Cliente aqui"
                );
        this.fieldBuscaCliente.setBackground(Color.red);
        JOptionPane.showMessageDialog(jPanelFilmes, "Selecione o Client aqui!"
                );
         this.fieldBuscaCliente.setBackground(null);
        
        //pintar linha da jtable
        
         JOptionPane.showMessageDialog(jPanelBuscaCliente, "Busque os filmes aqui!"
                 
                );
         this.jTextFieldBuscaFilme.setBackground(Color.LIGHT_GRAY);
          JOptionPane.showMessageDialog(jPanelBuscaCliente, "Selecione o Filme aqui!"
                );
          //pintar linha da jtable
            this.jTextFieldBuscaFilme.setBackground(null);
            
          
         
         
        
        
        
        
    }
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelBuscaCliente = new javax.swing.JPanel();
        comboBuscaCliente = new javax.swing.JComboBox();
        fieldBuscaCliente = new javax.swing.JTextField();
        consultarCliente = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableCliente = new javax.swing.JTable();
        selecionaCliente = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        nomeClienteReservas = new javax.swing.JTextField();
        efetuaReserva = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        tableReserva = new javax.swing.JTable();
        jLabel6 = new javax.swing.JLabel();
        nReserva = new javax.swing.JTextField();
        jPanelFilmes = new javax.swing.JPanel();
        jTextFieldBuscaFilme = new javax.swing.JTextField();
        comboBuscaFilme = new javax.swing.JComboBox();
        consultarFilme = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jButtonAdicionaFilmeReserva = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tableFilmes = new javax.swing.JTable();

        setClosable(true);
        setIconifiable(true);
        setTitle("Reservas");

        comboBuscaCliente.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        comboBuscaCliente.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Código", "Nome" }));
        comboBuscaCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboBuscaClienteActionPerformed(evt);
            }
        });

        fieldBuscaCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fieldBuscaClienteActionPerformed(evt);
            }
        });

        consultarCliente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/lupa.png"))); // NOI18N
        consultarCliente.setToolTipText("Procurar Cliente");
        consultarCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                consultarClienteActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Vrinda", 1, 18)); // NOI18N
        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/1Cliente.png"))); // NOI18N
        jLabel2.setText("Clientes:");

        tableCliente.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(tableCliente);

        selecionaCliente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/BuscaCliente.png"))); // NOI18N
        selecionaCliente.setText("Selecionar Cliente");
        selecionaCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selecionaClienteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelBuscaClienteLayout = new javax.swing.GroupLayout(jPanelBuscaCliente);
        jPanelBuscaCliente.setLayout(jPanelBuscaClienteLayout);
        jPanelBuscaClienteLayout.setHorizontalGroup(
            jPanelBuscaClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelBuscaClienteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelBuscaClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addGroup(jPanelBuscaClienteLayout.createSequentialGroup()
                        .addGroup(jPanelBuscaClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addGroup(jPanelBuscaClienteLayout.createSequentialGroup()
                                .addComponent(comboBuscaCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(fieldBuscaCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(consultarCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelBuscaClienteLayout.createSequentialGroup()
                        .addComponent(selecionaCliente)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanelBuscaClienteLayout.setVerticalGroup(
            jPanelBuscaClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelBuscaClienteLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelBuscaClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanelBuscaClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(fieldBuscaCliente, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(comboBuscaCliente, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(consultarCliente))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(selecionaCliente)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 404, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel3.setFont(new java.awt.Font("Vrinda", 1, 18)); // NOI18N
        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/Reservas.png"))); // NOI18N
        jLabel3.setText("Reservas:");

        jLabel4.setText("Cliente:");

        nomeClienteReservas.setEnabled(false);

        efetuaReserva.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/Salvar.png"))); // NOI18N
        efetuaReserva.setText("Efetuar Reserva");
        efetuaReserva.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                efetuaReservaActionPerformed(evt);
            }
        });

        tableReserva.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "CodProduto", "Nome Produto"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane3.setViewportView(tableReserva);
        tableReserva.getColumnModel().getColumn(0).setResizable(false);
        tableReserva.getColumnModel().getColumn(0).setPreferredWidth(3);
        tableReserva.getColumnModel().getColumn(1).setResizable(false);

        jLabel6.setText("Nº Reserva");

        nReserva.setEnabled(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 404, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(nReserva, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(efetuaReserva)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(nomeClienteReservas, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(13, 13, 13)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(nomeClienteReservas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(nReserva, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(efetuaReserva)
                .addGap(87, 87, 87))
        );

        comboBuscaFilme.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        comboBuscaFilme.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Código", "Nome" }));
        comboBuscaFilme.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboBuscaFilmeActionPerformed(evt);
            }
        });

        consultarFilme.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/lupa.png"))); // NOI18N
        consultarFilme.setToolTipText("Procurar Cliente");
        consultarFilme.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                consultarFilmeActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Vrinda", 1, 18)); // NOI18N
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/Filme.png"))); // NOI18N
        jLabel1.setText("Filmes:");

        jButtonAdicionaFilmeReserva.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/Mais.png"))); // NOI18N
        jButtonAdicionaFilmeReserva.setText("Adiciona Filme a Reserva");
        jButtonAdicionaFilmeReserva.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAdicionaFilmeReservaActionPerformed(evt);
            }
        });

        tableFilmes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane2.setViewportView(tableFilmes);

        javax.swing.GroupLayout jPanelFilmesLayout = new javax.swing.GroupLayout(jPanelFilmes);
        jPanelFilmes.setLayout(jPanelFilmesLayout);
        jPanelFilmesLayout.setHorizontalGroup(
            jPanelFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFilmesLayout.createSequentialGroup()
                .addComponent(comboBuscaFilme, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldBuscaFilme, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(consultarFilme, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanelFilmesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelFilmesLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanelFilmesLayout.createSequentialGroup()
                        .addGroup(jPanelFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 465, Short.MAX_VALUE)
                            .addGroup(jPanelFilmesLayout.createSequentialGroup()
                                .addComponent(jButtonAdicionaFilmeReserva)
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap())))
        );
        jPanelFilmesLayout.setVerticalGroup(
            jPanelFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelFilmesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanelFilmesLayout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(14, 14, 14)
                        .addGroup(jPanelFilmesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(comboBuscaFilme, javax.swing.GroupLayout.DEFAULT_SIZE, 28, Short.MAX_VALUE)
                            .addComponent(jTextFieldBuscaFilme)))
                    .addComponent(consultarFilme))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButtonAdicionaFilmeReserva)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 397, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(143, 143, 143))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanelBuscaCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelFilmes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 415, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelBuscaCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanelFilmes, javax.swing.GroupLayout.PREFERRED_SIZE, 538, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 0, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void comboBuscaClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboBuscaClienteActionPerformed

    }//GEN-LAST:event_comboBuscaClienteActionPerformed

    private void consultarClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_consultarClienteActionPerformed
            prencherTabelaClientes();
            
    }//GEN-LAST:event_consultarClienteActionPerformed
    public void prencherTabelaClientes(){

        ResultSet rs;
        try {
            rs = daoClientes.retornaCliente(fieldBuscaCliente.getText(),comboBuscaCliente.getSelectedIndex());
             ResultSetMetaData rsmetadata = rs.getMetaData();
             int columns = rsmetadata.getColumnCount();
              DefaultTableModel dtm = new DefaultTableModel(); 
              Vector colunsName = new Vector();
              Vector dataRows = new Vector();
                 for (int i = 1; i < columns; i++) {
            colunsName.addElement(rsmetadata.getColumnName(i));
        }
        dtm.setColumnIdentifiers(colunsName);
        while(rs.next()){
            dataRows = new Vector();
            for(int j = 1 ; j < columns;j++){
                dataRows.addElement(rs.getString(j));
            }
            dtm.addRow(dataRows);
            
        } 
            tableCliente.setModel(dtm);
            tableCliente.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        } catch (SQLException ex) {
            Logger.getLogger(TelaReservas.class.getName()).log(Level.SEVERE, null, ex);
        }
 
    }
        
    
    
    
    private void fieldBuscaClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fieldBuscaClienteActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_fieldBuscaClienteActionPerformed

    private void consultarFilmeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_consultarFilmeActionPerformed
        try {
            preencheTableFilmes();
        } catch (SQLException ex) {
            Logger.getLogger(TelaReservas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_consultarFilmeActionPerformed
   
    public void preencheTableFilmes() throws SQLException{
       ResultSet rsFilmes =  daoFilmes.retornFilmes(jTextFieldBuscaFilme.getText(), comboBuscaFilme.getSelectedIndex());
        
        ResultSetMetaData rsmetadata = rsFilmes.getMetaData();
        
        //nº de colunas
        int columns = rsmetadata.getColumnCount();
        System.out.println(columns);
        
        DefaultTableModel dtm = new DefaultTableModel();
        
        Vector colunsName = new Vector();
        Vector dataRows = new Vector();
        
        for (int i = 1; i < columns; i++) {
            colunsName.addElement(rsmetadata.getColumnName(i));
        }
        dtm.setColumnIdentifiers(colunsName);
        while(rsFilmes.next()){
            dataRows = new Vector();
            for(int j = 1 ; j < columns;j++){
                dataRows.addElement(rsFilmes.getString(j));
            }
            dtm.addRow(dataRows);
            
        } 
            tableFilmes.setModel(dtm);
            

    }

    
    private void comboBuscaFilmeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboBuscaFilmeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_comboBuscaFilmeActionPerformed

    private void selecionaClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selecionaClienteActionPerformed
        this.clienteSelecionado = true;
        try {
            String idClienteSelecionado = tableCliente.getValueAt(tableCliente.getSelectedRow(), 0).toString();
            ResultSet rs = daoClientes.retornaCliente(Integer.parseInt(idClienteSelecionado));
            while(rs.next()){
                
                this.nomeClienteReservas.setText(rs.getString("txtNomeCliente"));
            
                
            }
        } catch (SQLException ex) {
            Logger.getLogger(TelaReservas.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }//GEN-LAST:event_selecionaClienteActionPerformed

    private void jButtonAdicionaFilmeReservaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAdicionaFilmeReservaActionPerformed
      if(clienteSelecionado){
      
       Object idProdutoSelecionado = tableFilmes.getValueAt(tableFilmes.getSelectedRow(), 0).toString();
       Object tituloProdutoSelecionado = tableFilmes.getValueAt(tableFilmes.getSelectedRow(), 1).toString();
 
       
       DefaultTableModel dtm = new DefaultTableModel();

        Vector dataRows = new Vector();
        Vector colunsName = new Vector();
        colunsName.add("Código");
        colunsName.add("Titúlo");
        dtm.setColumnIdentifiers(colunsName);
        
        dataRows.addElement(idProdutoSelecionado);
        dataRows.addElement(tituloProdutoSelecionado);
      
        dtm.addRow(dataRows);
        
        //o esquema seria criar uma variavel da classse, o vector no caso, e dai ao inver de crirar ele aqui, só i
         
        
       
       tableReserva.setModel(dtm);
      }else{
          JOptionPane.showMessageDialog(this, "Primeiro Selecione o Cliente");
      }
      
    }//GEN-LAST:event_jButtonAdicionaFilmeReservaActionPerformed

    private void efetuaReservaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_efetuaReservaActionPerformed
        String idProdutoSelecionado = tableFilmes.getValueAt(tableFilmes.getSelectedRow(), 0).toString();
        String idClienteSelecionado = tableCliente.getValueAt(tableCliente.getSelectedRow(), 0).toString();
        if(daoFilmes.efetuaReserva(Integer.parseInt(idClienteSelecionado),Integer.parseInt(idProdutoSelecionado))==1){
           JOptionPane.showMessageDialog(this, "Reserva Efetuada Com sucesso");
        }else{
             JOptionPane.showMessageDialog(this, "Falha ao Efetuar Reserva");
            
        }
    }//GEN-LAST:event_efetuaReservaActionPerformed

    public boolean checaSelecaoCliente(){
        Object verifica = tableCliente.getValueAt(tableCliente.getSelectedRow(), 0);
        if(verifica == null){
            return false;
        }

        return true;
        
    }
    
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox comboBuscaCliente;
    private javax.swing.JComboBox comboBuscaFilme;
    private javax.swing.JButton consultarCliente;
    private javax.swing.JButton consultarFilme;
    private javax.swing.JButton efetuaReserva;
    private javax.swing.JTextField fieldBuscaCliente;
    private javax.swing.JButton jButtonAdicionaFilmeReserva;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanelBuscaCliente;
    private javax.swing.JPanel jPanelFilmes;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTextField jTextFieldBuscaFilme;
    private javax.swing.JTextField nReserva;
    private javax.swing.JTextField nomeClienteReservas;
    private javax.swing.JButton selecionaCliente;
    private javax.swing.JTable tableCliente;
    private javax.swing.JTable tableFilmes;
    private javax.swing.JTable tableReserva;
    // End of variables declaration//GEN-END:variables
}
